{% extends "base.html" %}

{% load humanize i18n page_metadata_tags %}

{% block metadata %}
    {% translate "Open" as trans_title %}
    {% page_metadata page_title=trans_title %}
{% endblock metadata %}

{% block body %}
    <div class="container">
        <div class="row">
            <div class="col-sm-6 col-md-5">
                <h1 class="text-6xl">{% translate "📊 Open" %}</h1>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6 col-md-3">
                <h2>{% translate "Tracking" %}</h2>
                <p>{{ total_users|intcomma }} {% translate "Users" %}</p>
                <p>{{ total_grids|intcomma }} {% translate "Grids" %}</p>
                <p>{{ total_categories|intcomma }} {% translate "Categories" %}</p>
                <p>{{ total_commits|intcomma }} {% translate "Commits" %}</p>
                <p>{{ total_versions|intcomma }} {% translate "Versions" %}</p>
                <h2>{% translate "Repos" %}</h2>
                <p>{{ repos_github|intcomma }} {% translate "GitHub Repos" %}</p>
                <p>{{ repos_bitbucket|intcomma }} {% translate "Bitbucket Repos" %}</p>
                <p>{{ repos_gitlab|intcomma }} {% translate "GitLab Repos" %}</p>
            </div>
            <div class="col-sm-6 col-md-3">
                <h2>{% translate "Packages" %}</h2>
                <p>{{ total_packages|intcomma }} {% translate "Packages" %}</p>
                {% for key, value in categories.items %}
                    <p>{{ value|intcomma }} {{ key }} {% translate "Packages" %}</p>
                {% endfor %}
                <p>{{ archive_packages|intcomma }} {% translate "Archived Packages" %}</p>
                <p>{{ deprecated_packages|intcomma }} {% translate "Deprecated Packages" %}</p>
            </div>
            <div class="col-sm-6 col-md-3">
                <h2>{% translate "Django Versions" %}</h2>
                <p>{% translate "Django 6.0 Packages:" %} {{ total_django_6_0|intcomma }}</p>
                <p>{% translate "Django 5.2 Packages:" %} {{ total_django_5_2|intcomma }}</p>
                <p>{% translate "Django 5.1 Packages:" %} {{ total_django_5_1|intcomma }}</p>
                <p>{% translate "Django 5.0 Packages:" %} {{ total_django_5_0|intcomma }}</p>
                <p>{% translate "Django 4.2 Packages:" %} {{ total_django_4_2|intcomma }}</p>
                <p>{% translate "Django 3.2 Packages:" %} {{ total_django_3_2|intcomma }}</p>
                <p>{% translate "Django 2.2 Packages:" %} {{ total_django_2_2|intcomma }}</p>
            </div>
            <div class="col-sm-6 col-md-3">
                <h2>{% translate "Python Versions" %}</h2>
                <p>{% translate "Python 3 Packages:" %} {{ total_python_3|intcomma }}</p>
                <p>{% translate "Python 3.15 Packages:" %} {{ total_python_3_15|intcomma }}</p>
                <p>{% translate "Python 3.14 Packages:" %} {{ total_python_3_14|intcomma }}</p>
                <p>{% translate "Python 3.13 Packages:" %} {{ total_python_3_13|intcomma }}</p>
                <p>{% translate "Python 3.12 Packages:" %} {{ total_python_3_12|intcomma }}</p>
                <p>{% translate "Python 3.11 Packages:" %} {{ total_python_3_11|intcomma }}</p>
                <p>{% translate "Python 3.10 Packages:" %} {{ total_python_3_10|intcomma }}</p>
            </div>
        </div>
    </div>

    <div class="container">
        <div class="row">
            <hr>

            <div class="col-sm-6 col-md-5">
                <h1>{% translate "💲 Funding" %}</h1>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-10 col-md-5">
                <canvas id="chart_funding_2023"></canvas>
            </div>
            <div class="col-sm-10 col-md-5">
                <canvas id="chart_funding_2022"></canvas>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-10 col-md-5">
                <canvas id="chart_funding_2021"></canvas>
            </div>
        </div>
    </div>

    <div class="container">
        <div class="row">
            <hr>

            <div class="col-sm-6 col-md-5">
                <h2>{% translate "Users who have contributed over ten packages" %}</h2>
                <table class="table">
                    <thead>
                        <tr>
                            <th>#</th>
                            <th>{% translate "User" %}</th>
                            <th>{% translate "Packages" %}</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for top_user in top_user_list %}
                            <tr>
                                <td>{% ifchanged top_user.num_packages %}{{ forloop.counter }}{% endifchanged %}</td>
                                <td><a href="{% url 'profile_detail' github_account=top_user.username %}">{{ top_user }}</a></td>
                                <td>{{ top_user.num_packages }} {% translate "packages" %}</td>
                            </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
            <div class="col-sm-6 col-md-5">
                <h2>{% translate "Grids with twenty-five or more packages" %}</h2>
                <table class="table">
                    <thead>
                        <tr>
                            <th>#</th>
                            <th>{% translate "Grid" %}</th>
                            <th>{% translate "Packages" %}</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for grid in top_grid_list %}
                            <tr>
                                <td>{% ifchanged grid.num_packages %}{{ forloop.counter }}{% endifchanged %}</td>
                                <td><a href="{{ grid.get_absolute_url }}">{{ grid }}</a></td>
                                <td>{{ grid.num_packages }} {% translate "packages" %}</td>
                            </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
        </div>
    </div>


    <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.min.js"></script>
    <script>


        function draw_chart(title, context, costData, incomeData) {
            const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];

            return new Chart(context, {
                type: 'line',
                data: {
                    labels: months, // x-axis labels
                    datasets: [{
                        label: 'Costs',
                        data: costData,
                        backgroundColor: 'rgba(255, 99, 132, 0.2)',
                        borderColor: 'rgba(255, 99, 132, 1)',
                        borderWidth: 1
                    }, {
                        label: 'Income',
                        data: incomeData,
                        backgroundColor: 'rgba(54, 162, 235, 0.2)',
                        borderColor: 'rgba(54, 162, 235, 1)',
                        borderWidth: 1
                    }]
                },
                options: {
                    title: {
                        display: true,
                        text: title
                    },
                    scales: {
                        yAxes: [{
                            scaleLabel: {
                                display: true,
                                labelString: 'Amount ($)'
                            },
                            ticks: {
                                beginAtZero: true,
                                callback: function(value, index, values) {
                                    return '$' + value;
                                }
                            }
                        }]
                    }
                }
            });
        }

        // 2023 data...

        const costsData2023 = [
            76.01,  // DigitalOcean 2023-01
            76.01,  // DigitalOcean 2023-02
            76.01,  // DigitalOcean 2023-03
            85.16,  // DigitalOcean 2023-04 - migrated slices
            46.43,  // DigitalOcean 2023-05
            46.43,  // DigitalOcean 2023-06
            46.43,  // DigitalOcean 2023-07
            61.65,  // DigitalOcean 2023-08
            61.63,  // DigitalOcean 2023-09
            61.63,  // DigitalOcean 2023-10
            61.63,  // DigitalOcean 2023-11
            61.63  // DigitalOcean 2023-12
        ];
        const incomeData2023 = [
            93.07,  // Ethical Ads 2023-01 + 2022-12
            0,      // Ethical Ads 2023-02
            80.38,  // Ethical Ads 2023-03
            0,  // 2023-04
            0,  // 2023-05
            0,  // 2023-06
            0,  // 2023-07
            25.61,  // Carbon Ads 2023-08
            25.58,  // Carbon Ads 2023-09
            22.58,  // Carbon Ads 2023-10
            16.95,  // Carbon Ads 2023-11
            0  // 2023-12
        ];
        draw_chart('Django Packages 2023', 'chart_funding_2023', costsData2023, incomeData2023);

        // 2022 data...

        const costsData2022 = [
            0,      // DigitalOcean Credit 2022-01
            63.24,  // DigitalOcean 2022-02
            71.08,  // DigitalOcean 2022-03
            71.08,  // DigitalOcean 2022-04
            71.08,  // DigitalOcean 2022-05
            71.08,  // DigitalOcean 2022-06
            71.08,  // DigitalOcean 2022-07
            82.30 + 29.97,  // DigitalOcean 2022-08 / Dynadot domain registration
            82.03,  // DigitalOcean 2022-09
            76.01,  // DigitalOcean 2022-10
            76.01,  // DigitalOcean 2022-11
            76.01   // DigitalOcean 2022-12
        ];
        const incomeData2022 = [
            62.90,  // Ethical Ads 2022-01
            55.13,  // Ethical Ads 2022-02
            66.18,  // Ethical Ads 2022-03
            70.98,  // Ethical Ads 2022-04
            66.21,  // Ethical Ads 2022-05
            59.12,  // Ethical Ads 2022-06
            55.05,  // Ethical Ads 2022-07
            0,
            92.23,  // Ethical Ads 2022-08 + 2022-09
            52.12,  // Ethical Ads 2022-10
            50.91,  // Ethical Ads 2022-11
            0
        ];

        draw_chart('Django Packages 2022', 'chart_funding_2022', costsData2022, incomeData2022);

        // 2021 data...

        const costsData2021 = [
            53.24,  // DigitalOcean 2021-01
            53.24,  // DigitalOcean 2021-02
            53.24,  // DigitalOcean 2021-03
            53.86,  // DigitalOcean 2021-04
            56.08,  // DigitalOcean 2021-05
            56.08,  // DigitalOcean 2021-06
            56.08,  // DigitalOcean 2021-07
            61.35,  // DigitalOcean 2021-08
            71.08,  // DigitalOcean 2021-09
            71.08,  // DigitalOcean 2021-10
            71.08,  // DigitalOcean 2021-11
            71.08   // DigitalOcean 2021-12
        ];
        const incomeData2021 = [
            0,  // 2021-01
            0,  // 2021-02
            0,  // 2021-03
            0,  // 2021-04
            0,  // 2021-05
            0,  // 2021-06
            0,  // 2021-07
            0,  // 2021-08
            0,  // 2021-09
            125.66,  // EthicalAds 2021-10
            87.46,  // EthicalAds 2021-11
            78.810  // EthicalAds 2021-12
        ];

        draw_chart('Django Packages 2021', 'chart_funding_2021', costsData2021, incomeData2021);

    </script>
{% endblock body %}
